package com.dingwei.superiordiary.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.mvp.presenter.ForgetPasswordPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.AppManager;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lihao on 2018/1/11.
 */

public class ForGetPasswordActivity extends BaseActivity implements Contract.ForgetPasswordView {

    ForgetPasswordPresenter forgetPasswordPresenter = new ForgetPasswordPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.et_phone)
    EditText etPhone;
    @Bind(R.id.btn_get_code)
    TextView btnGetCode;
    @Bind(R.id.et_code)
    EditText etCode;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.et_password1)
    EditText etPassword1;
    @Bind(R.id.btn_submit)
    Button btnSubmit;


    @Override
    protected int getContentViewId() {
        return R.layout.activity_forget_password;
    }

    @Override
    protected void initData() {

    }

    protected void initView() {
        tvTitle.setText("找回密码");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.btn_get_code, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                AppManager.getAppManager().finishActivity();
                break;
            case R.id.btn_get_code:
                forgetPasswordPresenter.getCode(etPhone.getText().toString());
                break;
            case R.id.btn_submit:
                forgetPasswordPresenter.forgetPassword(etPhone.getText().toString().trim(),etCode.getText().toString(),etPassword.getText().toString(),etPassword1.getText().toString());
                break;
        }
    }


    @Override
    public void CountDownTimerFinish() {
        btnGetCode.setTextColor(getResources().getColor(R.color.theme_color));
        btnGetCode.setText("获取验证码");
        btnGetCode.setEnabled(true);
    }

    @Override
    public void CountDownTimeronTick(long millisUntilFinished) {
        btnGetCode.setTextColor(getResources().getColor(R.color.text_color_gray));
        btnGetCode.setText("请等待" + millisUntilFinished / 1000 + "秒");
        btnGetCode.setEnabled(false);
    }

    @Override
    public void forgetPasswordSuccess() {
        AppManager.getAppManager().finishActivity();
    }
}
